<?php
/**
 * 后台订单管理控制器
 */
 class OrderController extends IsLoginController{
 	
	 public function index(){
	 	//查询分配订单信息
	 	$order = M('user_order')->JOIN("__user_order__ o join __order_list__ list join __goods__ g on o.oid = list.order_id AND list.goods_gid = g.gid")->group("oid")->all();
		$this->assign('order',$order);
	 	$this->display();
	 }
	 
	 //管理员发货
	 public function Ordersend(){
	 	$order = M('user_order')->JOIN("__user_order__ o join __order_list__ list join __goods__ g on o.oid = list.order_id AND list.goods_gid = g.gid")->where("order_status=1")->group("oid")->all();
		$this->assign('order',$order);
	 	$this->display();
	 }
	 
	 //已发货列表
	 public function send(){
	 	$order = M('user_order')->JOIN("__user_order__ o join __order_list__ list join __goods__ g on o.oid = list.order_id AND list.goods_gid = g.gid")->where("order_status=2")->group("oid")->all();
		$this->assign('order',$order);
	 	$this->display();
	 }
	 
	 //异步请求 处理发货
	 public function sendGoods(){
	 	if(IS_AJAX){
			$oid = Q('post.oid');
			//改变状态3为确认收货
			$data['order_status'] = 2;
			//写入数据库
			M('user_order')->where("oid ='{$oid}'")->update($data);
			$this->ajax('1');
	 	}
	 }
	
	//用户咨询管理
	public function question(){
		//全部回复
		$questionData = M()->JOIN("__goods__ g join __question__ q join __user__ u on q.goods_gid = g.gid and q.question_question_uid =u.uid ")->all();
		$this->assign('questionData',$questionData);
		$this->display();
	}
	
	//回答用户提问
	public function answer(){
		if(IS_AJAX){
			$qid = Q('post.qid');
			$data['question_answer'] = Q('post.con');
			$data['question_answer_uid'] = $_SESSION['uid'];
			$data['is_answer'] = 1;
			M('question')->where("qid='{$qid}'")->update($data);
			$this->ajax('1');
		}
	}
	
	//未回复问题
	public function noanswer(){
		//未回复
		$noanswer = M()->JOIN("__goods__ g join __question__ q join __user__ u on q.goods_gid = g.gid and q.question_question_uid =u.uid ")->where("is_answer = 0")->all();
		$this->assign('noanswer',$noanswer);
		$this->display();
	}
	
	//已回复列表
	public function answerok(){
		//已回复
		$answer = M()->JOIN("__goods__ g join __question__ q join __user__ u on q.goods_gid = g.gid and q.question_question_uid =u.uid ")->where("is_answer = 1")->all();
		$this->assign('answer',$answer);
		$this->display();
	}
	
	//评论管理
	public function comment(){
		//全部评论
		$questionData = M()->JOIN("__goods__ g join __comment__ c join __user__ u on c.goods_gid = g.gid and c.user_uid =u.uid ")->all();
		$this->assign('questionData',$questionData);
		$this->display();
	}
	
	//审核评论
	public function passCommet(){
		if(IS_AJAX){
			$cid = Q('post.cid');
			$data['comment_status'] =3;
			M("comment")->where("cid='{$cid}'")->update($data);
			$this->ajax('1');
		}
	}
	
	
	//锁定评论
	public function noPassComment(){
		if(IS_AJAX){
			$cid = Q('post.cid');
			$data['comment_status'] =1;
			M("comment")->where("cid='{$cid}'")->update($data);
			$this->ajax('1');
		}
	}
	
	//推荐评论
	public function recommend(){
		if(IS_AJAX){
			$cid = Q('post.cid');
			$data['comment_status'] =2;
			M("comment")->where("cid='{$cid}'")->update($data);
			$this->ajax('1');
		}
	}
	
	//删除
	public function delComment(){
		if(IS_AJAX){
			$cid = Q('post.cid');
			M("comment")->where("cid='{$cid}'")->del();
			$this->ajax('1');
		}
	}
	
	//锁定评论列表
	public function lockComment(){
		$questionData = M()->JOIN("__goods__ g join __comment__ c join __user__ u on c.goods_gid = g.gid and c.user_uid =u.uid ")->where("comment_status = 1")->all();
		$this->assign('questionData',$questionData);
		$this->display();
	}
	
	//未审核评论列表
	public function hotCommend(){
		$questionData = M()->JOIN("__goods__ g join __comment__ c join __user__ u on c.goods_gid = g.gid and c.user_uid =u.uid ")->where("comment_status = 0")->all();
		$this->assign('questionData',$questionData);
		$this->display();
	}
	
	//解除评论锁定
	public function rebackComment(){
		if(IS_AJAX){
			$cid = Q('post.cid');
			$data['comment_status'] =3;
			M("comment")->where("cid='{$cid}'")->update($data);
			$this->ajax('1');
		}
	}
	
 }